package com.usian.springbootmysql.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.usian.springbootmysql.pojo.ResultVo;
import com.usian.springbootmysql.pojo.SearchDto;
import com.usian.springbootmysql.pojo.TbCollege;
import com.usian.springbootmysql.service.CollegeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("college")
public class CollegeController {

    @Autowired
    private CollegeService collegeService;


    @RequestMapping("info")
    public TbCollege info(int id) {
        TbCollege tbCollege = collegeService.getById(id);
        return tbCollege;
    }

    @RequestMapping("save")
    public ResultVo save(@RequestBody TbCollege tbCollege) {
        return collegeService.saveCollege(tbCollege);
    }

    @RequestMapping("update")
    public ResultVo update(@RequestBody TbCollege tbCollege) {
        collegeService.updateById(tbCollege);
        return new ResultVo(200, "更新成功", null);
    }

    @RequestMapping("delete")
    public ResultVo delete(int id) {
        collegeService.removeById(id);
        return new ResultVo(200, "删除成功", null);
    }

    @RequestMapping("list")
    public ResultVo list() {
        List<TbCollege> list = collegeService.list();
        return new ResultVo(200, "success", list);
    }

    @RequestMapping("status")
    public ResultVo search(int status){
        List<TbCollege> list = collegeService.search(status);
        return new ResultVo(200,"success",list);
    }

    @RequestMapping("searchvo")
    public ResultVo searchvo(@RequestBody TbCollege tbCollege){
        List<TbCollege> list = collegeService.searchvo(tbCollege);
        return new ResultVo(200,"success",list);
    }

    @RequestMapping("page")
    public ResultVo page(int page,int size){
        Page<TbCollege> pages = new Page<TbCollege>(page, size);
        IPage<TbCollege> list = collegeService.page(pages);
        return new ResultVo(200,"success",list);
    }

    @RequestMapping("searchPage")
    public ResultVo searchPage(@RequestBody SearchDto searchDto){
        IPage<TbCollege> list = collegeService.searchPage(searchDto);
        return new ResultVo(200,"success",list);
    }

}
